<?php
include_once 'class/LogParser.acalss.inc';
include_once 'class/LogReader.aclass.inc';
class RadiusLogParser extends LogParser {
	private $pattern = '%(?P<date>(?P<month>\d{2})/(?P<day>\d{2})/(?P<year>\d{4})),(?P<time>\d{2}:\d{2}:\d{2}),(?P<UserName>[\w\s./\-@_:]*),(?P<GroupName>[\w\s./@\-&+:_]*),(?P<Calling_station_Id>[\w\s.\-:_]*),(?P<Called_station_Id>[\w\s./@\-:_]*),(?P<Login_IP_Host>[\w\s./@\-:_]*),(?P<Acct_Status_Type>[\w\s./@\-:_]*),(?P<Acct_Session_Time>[\d]*),(?P<Service_Type>[\w\s./@\-:_]*),(?P<Framed_Protocol>[\w\s./@\-:_]*),(?P<Framed_IP_Address>[\w\s./@\-:_]*),(?P<NAS_Identifier>[\w\s./@\-:_]*),(?P<NAS_Port_Id>[\w\s./@\-:_]*),(?P<NAS_Port>[\d]*),(?P<NAS_IP_Address>[\w\s./@\-:_]*),(?P<NAS_Port_Type>[\w\s./@\-:_]*),(?P<Acct_Session_Id>[\w\s./@\-:_]*),(?P<Acct_Delay_Time>[\d]*),(?P<Acct_Authentic>[\w\s./@\-:_]*),(?P<Acct_Input_Packets>[\d]*),(?P<Acct_Output_Packets>[\d]*),(?P<Acct_Input_Octets>[\d]*),(?P<Acct_Output_Octets>[\d]*),(?P<Acct_Terminate_Cause>[\w\s./@\-:_]*),(?P<Connect_Info>[\w]*)%';
	private $urlPattern = '/(?:\w+\:\/\/)?((?:(?:[[:alpha:]]\w*\.)+\w+)|(?:(?:\d{1,3}\.){3}\d{1,3}))/';
	/*
	public function __construct($log_reader){
		parent::__construct($log_reader);
	}
	*/
	protected function parser($log) {
		$matches = null;
		if(0 === preg_match($this->pattern, $log, $matches))
			return false;
		
		$res = array();
		$res['Date']=$matches['date'];
		$res['Day']=$matches['day'];
		$res['Month']=$matches['month'];
		$res['Year']=$matches['year'];
		$res['Time'] = $matches['time'];
		$res['UserName']= $matches['UserName'];
		$res['GroupName'] = $matches['GroupName'];
		$res['Calling_Station_Id'] = $matches['Calling_station_Id'];
		$res['Called_Station_Id'] = $matches['Called_station_Id'];
		$res['Login_IP_Host'] = $matches['Login_IP_Host'];
		$res['Acct_Status_Type'] = $matches['Acct_Status_Type'];
		$res['Acct_Session_Time'] = $matches['Acct_Session_Time'];
		$res['Service_Type'] = $matches['Service_Type'];
		$res['Framed_Protocol'] = $matches['Framed_Protocol'];
		$res['Framed_IP_Address'] = $matches['Framed_IP_Address'];
		$res['NAS_Identifier'] = $matches['NAS_Identifier'];
		$res['NAS_Port_Id'] = $matches['NAS_Port_Id'];
		$res['NAS_Port']= $matches['NAS_Port'];
		$res['NAS_IP_Address']= $matches['NAS_IP_Address'];
		$res['NAS_Port_Type']= $matches['NAS_Port_Type'];
		$res['Acct_Session_Id']= $matches['Acct_Session_Id'];
		$res['Acct_Delay_Time']= $matches['Acct_Delay_Time'];
		$res['Acct_Authentic']= $matches['Acct_Authentic'];
		$res['Acct_Input_Packets']= $matches['Acct_Input_Packets'];
		$res['Acct_Output_Packets']= $matches['Acct_Output_Packets'];
		$res['Acct_Input_Octets']= $matches['Acct_Input_Octets'];
		$res['Acct_Output_Octets']= $matches['Acct_Output_Octets'];
		$res['Acct_Terminate_Cause']= $matches['Acct_Terminate_Cause'];
		$res['Connect_Info']= $matches['Connect_Info'];
		return $res;
	}
	public function getDBVersion($log) {
		$res = array(
			'date'=> $log['Year']."-".$log['Month']."-".$log['Day']." ".$log['Time'],
			'username'=> $log['UserName'],
			'groupname'=> $log['GroupName'],
			'calling_station_id'=> $log['Calling_Station_Id'] ,
			'called_station_id'=> $log['Called_Station_Id'],
			'login_ip_host'=> $log['Login_IP_Host'] ,
			'acct_status_type'=> $log['Acct_Status_Type'],
			'acct_session_time'=> $log['Acct_Session_Time'] ,
			'service_type'=> $log['Service_Type'],
			'framed_protocol'=> $log['Framed_Protocol'] ,
			'framed_ip_address'=> $log['Framed_IP_Addlogs'],
			'nas_identifier'=> $log['NAS_Identifier'],
			'nas_port_id'=> $log['NAS_Port_Id'],
			'nas_port'=> $log['NAS_Port'],
			'nas_ip_address'=> $log['NAS_IP_Addlogs'],
			'nas_port_type'=> $log['NAS_Port_Type'],
			'acct_session_id'=> $log['Acct_Session_Id'],
			'acct_delay_time'=> $log['Acct_Delay_Time'],
			'acct_authentic'=> $log['Acct_Authentic'],
			'acct_input_packets'=> $log['Acct_Input_Packets'],
			'acct_output_packets'=> $log['Acct_Output_Packets'],
			'acct_input_octets'=> $log['Acct_Input_Octets'],
			'acct_output_octets'=> $log['Acct_Output_Octets'],
			'acct_terminate_cause'=> $log['Acct_Terminate_Cause'],
			'connect_info'=> $log['Connect_Info']
	);
	return $res;
	}
	
public function getName() {
		return 'radius';
	}
}
?>